package com.battery.system.service.battery.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import com.battery.common.utils.DateUtils;
import com.battery.system.domain.BO.Statistics;
import com.battery.system.domain.VO.ProjectVO;
import com.battery.system.mapper.UsedMapper;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.battery.system.mapper.ProjectMapper;
import com.battery.system.domain.Project;
import com.battery.system.service.battery.IProjectService;
import com.battery.common.core.text.Convert;

/**
 * 项目Service业务层处理
 *
 * @author battery
 * @date 2021-01-20
 */
@Service
public class ProjectServiceImpl extends BaseServiceImpl<Project> implements IProjectService {
    @Autowired
    private ProjectMapper projectMapper;


    @Autowired
    private UsedMapper usedMapper;


    /**
     * 查询项目
     *
     * @param id 项目ID
     * @return 项目
     */
    @Override
    public Project selectProjectById(String id) {
        return projectMapper.selectProjectById(id);
    }

    /**
     * 查询项目列表
     *
     * @param project 项目
     * @return 项目
     */
    @Override
    public List<Project> selectProjectList(Project project) {
        return projectMapper.selectProjectList(project);
    }

    /**
     * 新增项目
     *
     * @param project 项目
     * @return 结果
     */
    @Override
    public int insertProject(Project project) {
        project.setCreateTime(DateUtils.getNowDate());

        return projectMapper.insertProject(project);
    }

    /**
     * 修改项目
     *
     * @param project 项目
     * @return 结果
     */
    @Override
    public int updateProject(Project project) {

        project.setUpdateTime(DateUtils.getNowDate());
        return projectMapper.updateProject(project);
    }

    /**
     * 删除项目对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteProjectByIds(String ids) {
        return projectMapper.deleteProjectByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除项目信息
     *
     * @param id 项目ID
     * @return 结果
     */
    @Override
    public int deleteProjectById(String id) {
        return projectMapper.deleteProjectById(id);
    }

    @Override
    public List<ProjectVO> selectProjectVOList(Project project) {
        return projectMapper.selectProjectVOList(project);
    }

    @Override
    public Statistics selectProjectStatistics(String id, String day) {
        return projectMapper.selectProjectStatistics(id, day);
    }

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("dd");
        System.out.println(calendar.getTime());
        System.out.println(formatter.format(calendar.getTime()));
    }

    @Override
    public Statistics selectPartnerStatistics(String id, String day) {
        // 查看该合作商正在进行中的订单数量
        Long inOnUsedCount = usedMapper.selectInOnCountByPartnerId(id);
        Statistics statistics = projectMapper.selectPartnerStatistics(id, day);
        statistics.setInOnUsedCount(inOnUsedCount);
        return statistics;
    }

    @Override
    public Statistics selectMerchantStatistics(String id, String day) {
        return projectMapper.selectMerchantStatistics(id, day);
    }
}
